<?php
namespace Admin\Model;
use Think\Model;
class LiftlogModel extends Model {
    protected $autoCheckFields =false;
    protected $table ='user_lift_log';
	//授权升降级日志
	public function get_list($tp=1,$page=1,$pagesize=10,$where_data="",$order="g.ctime desc"){


      
        $where="";
		foreach ($where_data as $key => $value) {
			 $where.=" and  u.".$key." like '%".$value."%'";
		}

       
       //tp=1 升级 2=降级
       $where_data['tp']=$tp;
		if($tp>1)
		{
			$where_str="g.status=2";

		}
		else
		{
			$where_str="g.status=1";
		}


        $where_str.=$where;

		
		$info=M('user_lift_log')->alias('g')->join(' left JOIN tp_user as u  ON g.user_id = u.id')->where($where_str)->order($order)->page($page.','.$pagesize)->select();


		foreach ($info as $k => $v) {
			if($v['endtime']==0){
				$info[$k]['endtime']="永久";
			}else{
				$info[$k]['endtime']=date("Y-m-d",$v['endtime']);
			}

			$info[$k]['ctime']=date("Y-m-d H:i:s",$v['ctime']);
		}
		$count=M('user_lift_log')->join(' tp_user as u  ON g.user_id = u.id')->where($where_str)->count();


		$Page=new\Think\Page($count,$pagesize);	

		//分页跳转的时候保证查询条件

		foreach($where_data as $key=>$val) {
		    $Page->parameter[$key]   =   urlencode($val);
		}

		$show=$Page->show();
		return array("list"=>$info,"page"=>$show);
	}

	

}